﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Meqs.Entity;
using Meqs.Logic.Interface;

namespace Meqs.Logic.Implement
{
    public class ClassEvalRemarkLogic : CommonLogic<ClassEvalRemark, int>, IClassEvalRemarkLogic
    {
        private ISchoolInfoLogic _schoolLogic;
        public ClassEvalRemarkLogic(ISchoolInfoLogic schoolLogic)
        {
            _schoolLogic = schoolLogic;
        }

        #region Implementation of ICommonLogic<ClassEvalRemark, int>

        /// <summary>
        /// 创建对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Create(ClassEvalRemark entity)
        {
            return CreateObject(entity);
        }

        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(ClassEvalRemark entity)
        {
            return UpdateObject(entity);
        }

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public int Delete(int entityId)
        {
            return DeleteObject(entityId);
        }

        /// <summary>
        /// 删除所有对象
        /// </summary>
        /// <returns></returns>
        public int DeleteAll()
        {
            return DeleteAllObject();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public ClassEvalRemark FindById(int entityId)
        {
            return FindObjectById(entityId);
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount()
        {
            return FindObjectByCount();
        }

        /// <summary>
        /// 检索对象
        /// </summary>
        public IList<ClassEvalRemark> FindAll()
        {
            return FindAllObject();
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount(Hashtable table)
        {
            return FindObjectByCount(table);
        }

        /// <summary>
        /// 检索对象
        /// </summary>
        public IList<ClassEvalRemark> FindAll(Hashtable table)
        {
            return FindObject(table);
        }

        #endregion

        /// <summary>
        /// 获取指定班级指定评价单的指定备注
        /// </summary>
        public ClassEvalRemark GetRemarkByClass(int historyID, int classID, int reportType, DateTime evalDate, int? schoolYear, int? term, string schoolMark)
        {
            try
            {
                if (schoolYear == null || term == null)
                {
                    SchoolInfo school = _schoolLogic.FindBySchoolMark(schoolMark);
                    schoolYear = school.SchoolYear;
                    term = school.SchoolTerm;
                }
                Hashtable ht = new Hashtable();
                ht.Add("SchoolMark", schoolMark);
                ht.Add("ClassID", classID);
                ht.Add("ReportDate", evalDate);
                ht.Add("ReportType", reportType);
                ht.Add("SchoolYear", schoolYear);
                ht.Add("HistoryID", historyID);
                ht.Add("Term", term);
                return FindCustomerByID<ClassEvalRemark>("ClassEvalRemark.GetRemarkByClass", ht);
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="classEvalRemark"></param>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public int InserClassEvalRemark(ClassEvalRemark classEvalRemark, string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("ClassEvalRemark", classEvalRemark);
            ht.Add("SchoolMark", schoolMark);
            return (int)InsertCustomer("ClassEvalRemark.InsertClassEvalRemark", ht);
        }

    }
}
